<?php


namespace App\Http\Controllers\Weapp;


use App\Model\GoodsSku;
use App\Tool\Json;

class IndexModel extends Base
{


    /**
     * 广告轮播图
     * Create by Peter
     * 2020/07/07 14:57:21
     * Email:904801074@qq.com
     * @return false|string
     */
    function getAd()
    {

        $data = \Cache::get('index_ad', '');


        return Json::code(1, 'success', json_decode($data, true));

    }

    /**
     * 消息通知
     * Create by Peter
     * 2020/07/07 14:57:53
     * Email:904801074@qq.com
     * @return false|string
     */
    function getMessage()
    {
        $data = \Cache::get('index_message', '[]');


        return Json::code(1, 'success', json_decode($data, true));
    }

    /**
     * 模块
     * Create by Peter
     * 2020/07/07 14:58:11
     * Email:904801074@qq.com
     */
    function getMode()
    {

        $data = \Cache::get('index:mode_list', '[]');


        return Json::code(1, 'success', json_decode($data, true));

    }


    /**
     * 主页吸顶菜单的商品列表
     * Create by Peter
     * 2020/07/08 14:19:41
     * Email:904801074@qq.com
     */
    function getListWithFixedMenu()
    {

        $value = request()->input('value');

        $p = request()->input('p');

        $size = 10;

        $offset = ($p - 1) * $size;


        $list = [];

        switch ($value) {

            //新品
            case 1:

//                $list = \App\Model\Goods::with('goods_sku')->offset($offset)->limit($size)
//                    ->orderBy('id', 'desc')->get();


                $list=GoodsSku::with('goods')->with('snapped_sku.snapped')->offset($offset)->limit($size)
                    ->has('goods')
                    ->orderBy('id', 'desc')->get();



                break;

            default:

//                $list = \App\Model\Goods::with('goods_sku')->offset($offset)->limit($size)
//                    ->orderBy('id', 'asc')->get();


                $list=GoodsSku::with('goods')->with('snapped_sku.snapped')->offset($offset)->limit($size)
                    ->has('goods')
                    ->orderBy('id', 'asc')->get();

                break;

        }


        return Json::code(1, 'success', $list);

    }

}
